package com.yifang.yibingproject.utils;


import com.yifang.yibingproject.entity.BaseEntity;

import java.time.LocalDateTime;

/**
 * 实体工具类，要求实体继承父类BaseEntity
 */
public class EntityUtils {

    //初始化实体类
    public static <E extends BaseEntity> E init(E e) {
        e.setCreateTime(LocalDateTime.now());
        e.setCreateBy(SystemContext.getCurrentUserId());
        e.setUpdateTime(e.getCreateTime());
        e.setUpdateBy(e.getCreateBy());
        e.setIsDeleted(false);
        return e;
    }

    // 初始化实体类赋值UUID
    public static <E extends BaseEntity> E initWithUUID(E e) {
        init(e);
        return e;
    }

    //更新实体类
    public static <E extends BaseEntity> E update(E e) {
        e.setUpdateTime(LocalDateTime.now());
        e.setUpdateBy(SystemContext.getCurrentUserId());
        return e;
    }
}
